﻿<?php 
require_once '../../includefiles.php';
include_once("../../model/users.php");
require_once '../../model/admindetails.php';
include_once '../../model/email.php';


$userObj = new Model_Users();
$adminObj = new Model_AdminDetails();
$emailObj = new Model_Email();
## Check user login or not?
	$login_id = $_SESSION['getbids_id'];		
	
	if($login_id == ""){
	?> 
		<script type="text/javascript">		
		//SITEROOT = "http://192.168.1.42/getbids/";						
		SITEROOT = "<?php echo SITE_URL ?>/";
			
		var redirectPage = SITEROOT + "signin/";	
		window.parent.location.href = redirectPage;		
		
        </script>
 	<?php
		exit;		
	} 


$jobID =base64_decode($_GET['id1']);
$getjobdetil = $userObj->getJobDetailsById($jobID);
$smarty -> assign("getjobdetil",$getjobdetil);

//print_R($getjobdetil);die();
if(isset($_POST['submit']))
{
	extract($_POST);
	$userId = $_SESSION['getbids_id'];
	$userDetArray = $userObj->getUserDetailsByUserId($userId);
	
	$jobID =base64_decode($_GET['id1']);
	$getjobdetil = $userObj->getJobDetailsById($jobID);
	
	// code for add report abuse
	$reportabuseArray["userid"] 	= $userId;					
	$reportabuseArray["jobid"] 		= $jobID;
	$reportabuseArray["comment"] 		= $_POST['message'];
	$reportabuseArray["date_added"] = date('Y-m-d');
	$reportabuseId = $userObj->addReporttoabuse($reportabuseArray);
	
	// send email message to Admin
	$email_message = $emailObj->getEmailById(14);
	$e_subject = $email_message['email_subject'];
	$message = $email_message['email_content']; 
	
	$subject = str_replace('[SITENAME]', SITENAME, $e_subject);		 
	
	$message = str_replace('[NAME]', trim($userDetArray["first_name"])." ".trim($userDetArray["last_name"]) , $message);
	$message = str_replace('[JOBID]', "#PR".trim($getjobdetil["postjob_id"]), $message); 
	$message = str_replace('[JOBDESC]', trim($getjobdetil["job_desc"]), $message); 
	$message = str_replace('[HOME_NAME]', trim($getjobdetil["first_name"])." ".trim($getjobdetil["last_name"]) , $message);
	$message = str_replace('[HOME_NUMBER]', $getjobdetil["phone_number"], $message);
	$message = str_replace('[TRADE_NAME]', trim($userDetArray["firstname"])." ".trim($userDetArray["lastname"]) , $message);
	$message = str_replace('[COMMENT]', $_POST['message'], $message);
	$message = str_replace('[SITENAME]', SITENAME, $message);
	
	$adminEmail = $adminObj->getAdminDetails();
	$to = $adminEmail;
	$from = $userDetArray["email"];
	$fromname= SITENAME;
					 
	$emailTemplate = file_get_contents('../../emailtemplate.html');
	$template_msg = str_replace('[SITENAME]',SITENAME , $emailTemplate);
	$template_msg = str_replace('[LOGO]','<img src="'.SITE_URL.'/uploads/logo/'.$imageDetails.'">', $template_msg);
	$template_msg = str_replace('[MESSAGE]',$message,$template_msg); 
//	echo $from; exit;
	if(trim($to) != '')
	@send_mail($to, $template_msg, $subject, $from, $fromname); 
	
	
	//redirect_to_link(SITE_URL."/leads/".$_POST['jobid']."/buylead/");	
	$_SESSION['msg'] = "<div class='success_msg'><span>You have send abuse message successfully!</span></div>";
	//redirect_to_link(SITE_URL."/leads/myleads");
	
	
	?> 
		<script type="text/javascript">		
		SITEROOT = <?php echo SITE_URL ?>/";
			
		var redirectPage = SITEROOT + "leads/myleads";	
		window.parent.location.href = redirectPage;		
		
        </script>
 	<?php		
	exit;
} 
$smarty->display(TEMPLATEDIR . 'modules/leads/reportabuse.tpl');
?>